Minimize total cost